var $ = require('../../lib/jquery');
var util = require('./common/util');
var nav = require('./common/nav');
var _header = require('./common/header');
var template = require('../tpl/template');
var minHeight = require('./common/minHeight');
minHeight.init();
var _nav = new nav();
var header = new _header();
var helpshengzhi = {
  leftdom: '<div class="base df" data-parentId="{{parentId}}" data-id="{{id}}"><span>{{name}}</span><span>></span></div>',
  rightdom: '<div class="block" > <p class="name name{{index}} bb"><span>{{name}}</span></p> {{contdom}}</div>',
  contdom: '<p class="jg bb " > {{name}}</p> ',
  init: function (medicalid) {
    this.fetch();
    this.bindevent();
  },
  fetch: function (medicalid) {
    var _this = this;
    util.fetch('api/art/queryList').then(function(res){
        _this.render(res.data[0]);
    }).fail(function (){
      console.log('接口挂了')
    })
  },
  render: function (data) {
    var left = '';
    var right = '';
    var rightdom =''
    for(var i = 0; i<data.list.length;i++){
      var item = data.list[i];
      left += this.leftdom.replace('{{name}}', item.name).replace('{{parentId}}', item.parentId).replace('id',item.id);
      right = this.rightdom.replace('{{name}}', item.name).replace('{{index}}', i);
      var tpl = ''
        for(var j=0;j<item.list.length;j++){
          var k = item.list[j];
          tpl +=this.contdom.replace('{{name}}',k.name)
        }
      rightdom += right.replace('{{contdom}}',tpl);
    }
    $('.js_left').html(left);
    $('.js_right').html(rightdom)

  },
  bindevent: function (medicalid) {
    $('body').on('click', '.js_index', function(){
      location.href = './index.html'
    })
  }
}
helpshengzhi.init();